How can I run an automation template

Oyin 20 Reputation points
2024-05-08T00:16:54.5566667+00:00

I want to run an automation template for a sql database deployed with ARM. The aim is to trigger a stored procedure

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,914 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,144 questions
0 comments No comments
{count} votes

Accepted answer
  1. akinbade abiola 1,885 Reputation points
    2024-05-13T09:32:20.0466667+00:00

    Hello,

    Thanks for your question.

    To do this I will recommend using a managed identity with the appropriate resource contributor permissions on least privilege scope

    You can get the access token using:
    $Token = (Get-AZAccessToken -ResourceUrl https://database.windows.net).Token

    you can then use Invoke-Sqlcmd to execute the stored procedure requirement

    https://learn.microsoft.com/en-us/powershell/module/sqlserver/invoke-sqlcmd?view=sqlserver-ps

    See an example here to execute stored procedure.

    Invoke-Sqlcmd -ServerInstance $Server -Database $db -AccessToken $token `

             -Query "exec [dbo].[procedure] @Operation='all', @LogToTable=1" `
    
             -QueryTimeout 65535 -ConnectionTimeout 60 -Verbose
    

    Also consider setting appropriate schedules and variables for your automation account depending on your use case.

    https://learn.microsoft.com/en-us/azure/automation/shared-resources/schedules
    https://learn.microsoft.com/en-us/azure/automation/shared-resources/variables?tabs=azure-powershell

    Please let me know if you have further questions

    You can mark it 'Accept Answer' if this helped.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ruel G. Cabusas 205 Reputation points
    2024-05-08T08:05:53.83+00:00

    Hi Oyin,

    Have you tried/ considered using Logic Apps?

    You can view the documentation in here; https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-overview

    0 comments No comments